<template>
  <view class="register-container">
<!-- 	<view class="input-group">
	  <input v-model="firm" placeholder="请输入公司" class="input" />
	</view> -->
	<view class="input-group">
		<uni-data-select
		  v-model="firm"
		  :localdata="range"
		  @change="change"
		  placeholder="请选择公司"
		></uni-data-select>
	</view>


	<view class="input-group">
	  <uni-easyinput v-model="idnumber" placeholder="请输入工号"  />
	</view>
	<view class="input-group">
	  <uni-easyinput v-model="realname" placeholder="请输入姓名"  />
	</view>
    <view class="input-group">
      <uni-easyinput v-model="username" placeholder="请输入用户名"  />
    </view>
    <view class="input-group">
      <uni-easyinput v-model="password" type="password" placeholder="请输入密码"  />
    </view>
    <view class="input-group">
      <uni-easyinput v-model="confirmPassword" type="password" placeholder="确认密码"/>
    </view>
    <view class="btn-container">
      <button @click="register" class="button">注册</button>
    </view>
    <view class="login-link">
      <text @click="goToLogin">已有账号？去登录</text>
    </view>
  </view>
</template>

<script>
import common from  "../common/js/common.js";
export default {
  data() {
    return {
      username: '',
      password: '',
      confirmPassword: '',
	  firm: '',
	  idnumber: '',
	  realname: '',
	  permissionLevel: -1,
		range: [
		  { value: "QQCTN", text: "QQCTN" },
		  { value: "盈泰军恒", text: "盈泰军恒" },
		  { value: "鑫众合", text: "鑫众合" },
		  { value: "阳都正海", text: "阳都正海" },
		  { value: "缘洋", text: "缘洋" },
		],
	  firmOptions: ['QQCTN', '盈泰军恒', '鑫众合', '阳都正海', '缘洋']
    };
  },
  methods: {
	 change(e) {
			
	  },
    register() {
      if (this.username && this.password && this.password === this.confirmPassword) {
		const query = {
			'action': "add",
			'username': this.username,
			'password': this.password,
			'firm': this.firm,
			'idnumber': this.idnumber,
			'realname': this.realname,
		}
		uni.request({
				url: common.baseurl + '/api/user/info',
				method:'POST',
				data: query,
			}).then(data=>{
				console.info(data[1].data)
				this.permissionLevel = data[1].data.permissionLevel
				this.ships = data[1].data
			}).catch(()=>{

			})
        uni.redirectTo({ url: '/pages/login' }); // 注册成功后跳转到个人页面
      } else {
        uni.showToast({
          title: '请填写有效信息或确认密码一致',
          icon: 'none',
        });
      }
    },
    goToLogin() {
      uni.redirectTo({ url: 'login' }); // 跳转到登录页面
    }
  }
};
</script>

<style scoped>
.register-container {
  padding: 30px;
}
.input-group {
  margin-bottom: 20px;
}
.input {
  width: 100%;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
}
.button {
  width: 100%;
  background-color: #007AFF;
  color: white;
  border-radius: 5px;
  border: none;
  font-size: 16px;
}
.login-link {
  margin-top: 10px;
  text-align: center;
}
.login-link text {
  color: #007AFF;
}
</style>
